#include<iostream>
#include<fstream>
#include<sstream>
#include<log4cpp/Category.hh>
#include<log4cpp/Priority.hh>
/* #include<log4cpp/Layout.hh> */
/* #include<log4cpp/BasicLayout.hh> */
#include<log4cpp/PatternLayout.hh>
#include<log4cpp/OstreamAppender.hh>
/* #include<log4cpp/Appender.hh> */
#include<log4cpp/RollingFileAppender.hh>
#include<log4cpp/FileAppender.hh>

using namespace log4cpp;
using std::cout;
int main(void)
{
    //新建布局
    PatternLayout * ptn =new PatternLayout();
    ptn->setConversionPattern("%d [%c] %p %m %n");

    PatternLayout * ptn1 =new PatternLayout();
    ptn1->setConversionPattern("%d [%c] %p %m %n");

    PatternLayout * ptn2 =new PatternLayout();
    ptn2->setConversionPattern("%d [%c] %p %m %n");

    //创建目的地
    /* OstreamAppender * pos=new OstreamAppender("appender",&cout); */
    auto *pos =new OstreamAppender("appender cout",&cout);
    pos->setLayout(ptn);

    FileAppender * filepos=new FileAppender("file","a.log");
    filepos->setLayout(ptn1);

    RollingFileAppender* rollpos=new RollingFileAppender("roll file","muti.log",1024,9);
    rollpos->setLayout(ptn2);

    //设置category
    Category & sub= Category::getRoot().getInstance("sub");

    //绑定目的地设定优先级
    
    sub.setPriority(Priority::INFO);
    sub.addAppender(pos);
    sub.addAppender(filepos);
    sub.addAppender(rollpos);

    //打印输出
    int num=100;
    while(num-->0)
    {

    sub.emerg("test emerg");
    sub.fatal("test fatal");
    sub.alert("test alert");
    sub.crit("test crit");
    sub.error("test error");
    sub.warn("test warn");
    }
    /* sub.shutdown(); */
}
